package graph.group.zhangtao.guider.homepage.activities;

import android.content.Intent;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;

import graph.group.zhangtao.guider.R;

/**
 * Created by T5 on 2016/6/16.
 */
public abstract class BaseActivity extends AppCompatActivity {

    private RelativeLayout rlContent;
    private Toolbar toolbar;
    private ToolBarX  mToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.AppTheme);
        setContentView(R.layout.base_layout);
        initialize();
        View v = getLayoutInflater().inflate(getLayoutId(),rlContent,false);
        rlContent.addView(v);
        mToolbar = new ToolBarX(toolbar,this);
    }

    public abstract int getLayoutId();

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        overridePendingTransition(R.anim.anim_in_right_to_left, R.anim.anim_out_righ_to_left);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.anim_in_left_to_right,R.anim.anim_out_left_to_right);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        overridePendingTransition(R.anim.anim_in_right_to_left, R.anim.anim_out_righ_to_left);
    }

    private void initialize(){
        rlContent = (RelativeLayout) findViewById(R.id.rlContent);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
    }

    public ToolBarX getToolbar(){
        if (mToolbar==null){
            mToolbar = new ToolBarX(toolbar,this);
        }
        return mToolbar;
    }

    public Toolbar getOriginalToolbar(){
        return this.toolbar;
    }
}
